package org.grow.wsing.stomp;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;

/**
 * @Author: xwg
 * @CreateDate: 2025/10/17
 */

@Configuration
@EnableWebSocketMessageBroker
public class StompConfig implements WebSocketMessageBrokerConfigurer {

    @Autowired
    private AuthHandShake authHandShake;
    @Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {
            registry.addEndpoint("/chatting")
                    .setHandshakeHandler(authHandShake)
//                    .addInterceptors()
                    .setAllowedOriginPatterns("*");
    }

    @Override
    public void configureMessageBroker(MessageBrokerRegistry registry) {
//        channel用来广播 p2p用来私聊
        registry.enableSimpleBroker("/channel","/p2p");
        registry.setUserDestinationPrefix("/single");
//        /chatMessage/insert
        registry.setApplicationDestinationPrefixes("/chatMessage");
    }
}
